/**
 * @brief TCP Client Peer.
 *
 * @author Huang RuiGuang
 * @date 2008/12/1
 *
 * Herm library
 * Copyright (c) 2008 by Huang RuiGuang(daemon.huang@gmail.com)
 *
 * Permission to use, copy, modify, distribute and sell this software.
 */
#ifndef HERM_SOCKET_TC_PEER_H
#define HERM_SOCKET_TC_PEER_H

#include "herm/base/network/interface.h"
#include "herm/base/network/accept_handler.h"
#include "herm/base/network/helper.h"

namespace herm{
	class Multiplexor;
	class Address;
}

class TCPeer : public herm::IPeer
{
public:
	TCPeer();
	~TCPeer();

	void Reset(herm::Multiplexor* multiplexor, herm::IListener* listener, 
		const herm::TCPeerParam& peerParam);
	void Reconnect(TCPSession* tcSession);

	inline TCPSessionObjMgr* GetSessions() const
	{
		return m_tcpSessionObjMgr;
	}

	inline NBCTCPSessionObjMgr* GetNBCSessions() const
	{
		return m_nbcTCPSessionObjMgr;
	}
private:
	virtual herm::ISession* CreateSession(const std::string& servName, 
		const herm::Address& remoteAddr, bool needReconnect, bool isBlock, 
		herm::INBCNotifier* notifier);
	virtual herm::ISession* GetSession(int) { return nullptr; }
	virtual void DestroySession(int sessinIdx);
	virtual void Finish(){}
	virtual herm::IListener* GetListener() const;

	herm::ISession* CreateSession(const std::string& servName, 
		const herm::Address& remoteAddr, bool needReconnect);
	herm::ISession* CreateNBConnSession(const herm::Address& remoteAddr, 
		herm::INBCNotifier* notifier);
private:	
	TCPSessionObjMgr* m_tcpSessionObjMgr;
	NBCTCPSessionObjMgr* m_nbcTCPSessionObjMgr;
	herm::Address m_localAddr;
	herm::IListener* m_listner;
	herm::TCPeerParam m_peerParam;
	char* m_tmpBuf;
};

#endif
